package com.wlyuan.index.domain.index.valueobj;

import lombok.Data;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

import static com.wlyuan.index.domain.index.valueobj.Bill.Status.CAN_BILL;

/**
 * @author yuanjie
 */
@Data
@Deprecated
public class Bill {
    public static final Integer ENDED = 1;

    public interface Status {
        Integer RECALLED = -2; // 已关闭
        Integer CLOSED = -1; // 已关闭
        Integer AUDITING = 10; // 待审核
        Integer DRAFT = 0; // 草稿
        Integer RETURNED = 30; // 已退回
        Integer MAX = 100;
        List<Integer> CAN_BILL = Arrays.asList(RETURNED, CLOSED, RECALLED, AUDITING);
    }

    @Field(type = FieldType.Long)
    private Long billId;
    @Field(type = FieldType.Keyword)
    private String billNo;
    @Field(type = FieldType.Keyword)
    private String name;
    @Field(type = FieldType.Integer)
    private Integer status;
    @Field(type = FieldType.Date, format = DateFormat.custom, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
    private LocalDateTime createAt;

    public int getPriority() {
        if (null == this.status) {
            return 0;
        }

        // 草稿状态对账单优先级最高
        if (Status.DRAFT.equals(this.getStatus())) {
            return Status.MAX;
        }
        return this.getStatus();
    }

    public static boolean canBill(Integer status) {
        return null == status || CAN_BILL.contains(status);
    }
}